# -*- coding: utf-8 -*-
import KBEngine
from KBEDebug import *

import IKernel

#引擎代理实体：用来管理底层引擎发到逻辑层的回调函数
engineProxy = None

def onInit(isReload):
	"""
	KBEngine method.
	当引擎启动后初始化完所有的脚本后这个接口被调用
	"""
	DEBUG_MSG('onInit::isReload:%s' % isReload)

	global engineProxy
	if engineProxy != None:
		args = []
		args.append(isReload)
		IKernel.Instance().onEvent(engineProxy.getScriptName(), "onInit", engineProxy.id, engineProxy.id, args)

def onGlobalData(key, value):
	"""
	KBEngine method.
	globalData改变 
	"""
	DEBUG_MSG('onGlobalData: %s' % key)

	global engineProxy
	if engineProxy != None:
		args = []
		args.append(key)
		args.append(value)
		IKernel.Instance().onEvent(engineProxy.getScriptName(), "onGlobalData", engineProxy.id, engineProxy.id, args)

def onGlobalDataDel(key):
	"""
	KBEngine method.
	globalData删除 
	"""
	DEBUG_MSG('onDelGlobalData: %s' % key)

	global engineProxy
	if engineProxy != None:
		args = []
		args.append(key)
		IKernel.Instance().onEvent(engineProxy.getScriptName(), "onGlobalDataDel", engineProxy.id, engineProxy.id, args)

def onCellAppData(key, value):
	"""
	KBEngine method.
	cellAppData改变 
	"""
	DEBUG_MSG('onCellAppData: %s' % key)

	global engineProxy
	if engineProxy != None:
		args = []
		args.append(key)
		args.append(value)
		IKernel.Instance().onEvent(engineProxy.getScriptName(), "onCellAppData", engineProxy.id, engineProxy.id, args)

def onCellAppDataDel(key):
	"""
	KBEngine method.
	cellAppData删除 
	"""
	DEBUG_MSG('onCellAppDataDel: %s' % key)

	global engineProxy
	if engineProxy != None:
		args = []
		args.append(key)
		IKernel.Instance().onEvent(engineProxy.getScriptName(), "onCellAppDataDel", engineProxy.id, engineProxy.id, args)

def onSpaceData( spaceID, key, value ):
	"""
	KBEngine method.
	spaceData改变
	"""

	global engineProxy
	if engineProxy != None:
		args = []
		args.append(spaceID)
		args.append(key)
		args.append(value)
		IKernel.Instance().onEvent(engineProxy.getScriptName(), "onSpaceData", engineProxy.id, engineProxy.id, args)

def onAllSpaceGeometryLoaded( spaceID, isBootstrap, mapping ):
	"""
	KBEngine method.
	space 某部分或所有chunk等数据加载完毕
	具体哪部分需要由cell负责的范围决定
	"""

	global engineProxy
	if engineProxy != None:
		args = []
		args.append(spaceID)
		args.append(isBootstrap)
		args.append(mapping)
		IKernel.Instance().onEvent(engineProxy.getScriptName(), "onAllSpaceGeometryLoaded", engineProxy.id, engineProxy.id, args)








































